//
//  XMMessageFactory.m
//  XMMessageKit
//
//  Created by lishi on 2019/3/5.
//  Copyright © 2019 lishi. All rights reserved.
//

#import "XMMessageFactory.h"

// Model
#import "XMMessageModel.h"

// View
#import "XMMessageTextTableCell.h"
#import "XMMessageImageTableCell.h"



@implementation XMMessageFactory

//+ (XMBaseMessageTableCell *)factoryWithType:(XMMessageFactoryType)type {
//    switch (type) {
//        case XMMessageFactoryTypeText:
//        {
//            return [[XMMessageTextTableCell alloc] init];
//        }
//            break;
//        case XMMessageFactoryTypeImage:
//        {
//            return [[XMMessageImageTableCell alloc] init];
//        }
//            break;
//        default:
//            break;
//    }
//    return nil;
//}


+ (XMBaseMessageTableCell *)creatCellWithModel:(XMMessageModel *)model {
    Class classForCell = NSClassFromString(model.messageType);
    XMBaseMessageTableCell *cell = nil;
    if ([model.messageType isEqualToString:@"XMMessageTextTableCell"]) {
        cell = [[XMMessageTextTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(classForCell)];
    } else if ([model.messageType isEqualToString:@"XMMessageImageTableCell"]) {
        cell = [[XMMessageImageTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(classForCell)];
    }
    [cell setUpValueForCellMessageWithModel:model];
    return cell;
    
//    Class classForCell = NSClassFromString(model.messageType);
//    XMBaseMessageTableCell *cell = nil;
//    switch (model.type) {
//        case XMMessageTypeText:
//        {
//            cell = [[XMMessageTextTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(classForCell)];
//        }
//        break;
//        case XMMessageTypeImage:
//        {
//            cell = [[XMMessageImageTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(classForCell)];
//        }
//            break;
//        default:
//            break;
//    }
//    [cell setUpValueForCellMessageWithModel:model];
    return cell;
    
//    Class classForCell = NSClassFromString(model.messageType);
//    XMBaseMessageTableCell *cell = [[classForCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(classForCell)];
//    [cell setUpValueForCellMessageWithModel:model];
//    return cell;
}

@end
